package com.framework.dubbo.consumer;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;

import com.framework.dubbo.DemoService;
import com.framework.dubbo.FileSystemConfig;
import com.framework.dubbo.Pdf2HtmlService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.Reference;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;

@EnableAutoConfiguration
public class DubboConsumerBootstrap {

    private final Logger logger = LoggerFactory.getLogger(getClass());


    /**
     * 不知道为啥需要重新指定一次版本号
     */
    @DubboReference(version = "2.0.0")
    private DemoService demoService;
    /**
     * 不知道为啥需要重新指定一次版本号
     */
    @DubboReference(version = "2.0.0")
    private Pdf2HtmlService pdf2HtmlService;

    public static void main(String[] args) {

        SpringApplication.run(DubboConsumerBootstrap.class).close();
    }

    @Bean
    public ApplicationRunner runner() throws Exception {
        TimeInterval timer = DateUtil.timer();
        String s = pdf2HtmlService.pdf2Str(getFileSystemConfig(), "/heneng/hn_data/6261383fc7b842baa02ce2454f39f3aa.pdf", true);
        System.out.println("结果是" + s);
        String provider = demoService.sayHello("这是用于测试的测试数据");
        System.out.println("用时"+timer.interval() + "ms");
        return args -> logger.info(provider);
    }

    private FileSystemConfig getFileSystemConfig() {

        FileSystemConfig fileSystemConfig = new FileSystemConfig();
        fileSystemConfig.setAccessKey("admin");
        fileSystemConfig.setBucketName("heneng");
        fileSystemConfig.setDownloadPrefix("/minio/download/");
        fileSystemConfig.setEndpoint("http://192.168.1.37:9000");
        fileSystemConfig.setRunningDirs("hn_running");
        fileSystemConfig.setSecretKey("admin123456");
        fileSystemConfig.setSourceDirs("hn_data");
        fileSystemConfig.setTargetDirs("hn_result");
        return fileSystemConfig;
    }

}
